package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.CloudCurriculumSearchResultPresenter
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.CloudCurriculumSearchResultView
import com.weetop.cfw.bean.AudioVideoBrowsingRecordBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.home_page.fragment.CloudCurriculumSearchResultFragment
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class CloudCurriculumSearchResultPresenterImp(var cloudCurriculumSearchResultView: CloudCurriculumSearchResultView? = null):CloudCurriculumSearchResultPresenter {
    /**
     * 获取云课程数据列表
     */
    override fun getCloudCurriculumDataList(cloudCurriculumSearchResultFragment: CloudCurriculumSearchResultFragment, classid: Int, key: String, curpage: Int) {
        cloudCurriculumSearchResultFragment.showLoadingDialog(cloudCurriculumSearchResultFragment.activity!! as CommonBaseActivity,"正在获取云课程列表数据...")
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getVideoListData(classid = classid,Key = key,curpage = curpage),cloudCurriculumSearchResultFragment,object:
            RxJavaCallBack<AudioVideoBrowsingRecordBean>(){
            override fun onSuccess(t: AudioVideoBrowsingRecordBean?) {
                cloudCurriculumSearchResultFragment.dismissLoadingDialog()
                cloudCurriculumSearchResultView?.cloudCurriculumListDataGetSuccess(t)
            }

            override fun onRequestError(t: AudioVideoBrowsingRecordBean?) {
                super.onRequestError(t)
                cloudCurriculumSearchResultFragment.dismissLoadingDialog()
                cloudCurriculumSearchResultView?.cloudCurriculumListDataGetFailed()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                cloudCurriculumSearchResultFragment.dismissLoadingDialog()
                cloudCurriculumSearchResultView?.cloudCurriculumListDataGetFailed()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        cloudCurriculumSearchResultView = baseView as? CloudCurriculumSearchResultView
    }

    /**
     * 解绑
     */
    override fun detachView() {
        cloudCurriculumSearchResultView = null
    }
}